package cn.lanqiao.demo.dao;

import cn.lanqiao.demo.entity.Teacher;
import cn.lanqiao.demo.entity.Vaccine;
import cn.lanqiao.demo.vo.TeacherVaccineVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface TeacherDao {
    //查询男女
    @Select("select Tsex name,count(*) value FROM teacher GROUP BY tsex;")
    public List<Map<String,Integer>> getSex();

    //展示全部teacher信息方法
    @Select("select t.* ,v.inoculated from teacher t left join vaccine v on t.Tno =v.Vno")
    public List<TeacherVaccineVO> getAll();

    //根据教师工号查找教师信息方法
    @Select("select t.* ,v.inoculated from teacher t left join vaccine v on t.Tno =v.Vno where t.Tno=#{Tno}")
    public TeacherVaccineVO getId(String Tno);

    //教师修改方法
    @Update("update teacher t join vaccine v on t.Tno=v.Vno set t.Tname =#{Tname},t.Tage=#{Tage},t.Tbirth=#{Tbirth},t.Tsex=#{Tsex},v.inoculated=#{inoculated} where t.Tno=#{Tno}")
    public int update(TeacherVaccineVO teacherVaccineVO);

    //根据教师id删除信息
    @Delete("DELETE teacher,vaccine FROM teacher LEFT JOIN vaccine ON teacher.Tno=vaccine.Vno WHERE teacher.Tno=#{Tno}")
    public int delete(String Tno);

    //增加教师信息方法
    @Insert("INSERT INTO teacher (Tno,Tname,Tage,Tbirth,Tsex) VALUES(#{Tno},#{Tname},#{Tage},#{Tbirth},#{Tsex})")
    public int insert(Teacher teacher);

    //连表增加疫苗信息方法
    @Insert("INSERT INTO vaccine (Vno) SELECT Tno from teacher where teacher.Tno=#{Tno}")
    public int insertTV(String Tno);



}
